So let's put a message frame on our window so that when we get we get some sort of information we want
to give the user, it's going to display up top.
I'm going to go to my starter g UI screen, g UI shop frame, top bar frame.
And on that when I hit the plus sign, I'm going to add text label.
There we go.
And I'm going to call this message label if I can click it.
There we go.
I got it.
Message label.
I'm going to make the anchor ..5.5 because I'm going to center it on this top, this top bar frame.
I take that anchor point right there and put it in the center.
So.
Well, while we're here on background transparency, if you can't quite see that, let me move that
out.
Background transparency.
Let's make that a one.
Right.
We don't need the background and let's go down a little more position.
All right?
This is what's going to change where my my labels at 0.5 on the X comma, zero pixel offset comma 0.5
and the Y comma, zero pixel offset.
All right.
And then the size well, let's see, X, we don't want to make it the full size.
The demo I made a 0.6.
I think I'm going to make a 0.8 on the x zero pixel offset and then one for the Y.
That's the full height of the bar.
Zero pixel offset.
Oh, that's good.
Yeah, that'll work.
That'll work.
Let's scroll down a little more and I'm going to change the font face to comic.
So we make a bold.
Sure.
And then the text, I'm going to actually clear that out, but not until I'm done with everything else.
Make the text color three.
I'm going to make that like a really red.
Because we want them to read it and then text scale.
You can try and pick a text size, but just be aware that you want that text size to change depending
on the window size.
We've already run into problems with that, so we could put a little text transparency around it too,
if you want.
Maybe we'll do that.
So text stroke, transparency, make that zero.
That makes it pretty easy to see.
Might be a little too much.
I think I'll keep it, though.
All right.
Now I can get rid of that label.
We know what everything looks like.
There we go.
Now let's add some code so that we can send messages to our message label if something goes wrong with
the purchase.
I'm going to open up my shop script, which is under the shop frame, which is in the screen.
Gooey.
There we go.
Opened it up and near the top in the variable section.
The last variable.
And you.
But you could add it anywhere.
I'm going to add a variable or message label and it's going to be on the shop frame, top bar frame.
And it is called message label.
Nice.
All right.
Now I see this preview item where we when we click on our items, we're going to get our image and the
text and the price.
I'm going to use this.
I'm going to copy this.
Control C and then right underneath it, Control V, I'm going to make another function called Clear
Fields and I'm going to get rid of I'm going to get rid of that button.
I don't need it.
What I really needed were these three values.
So I have my preview image.
I'm going to delete that value that I'm assigning because we're clearing the fields here and I'll delete
this one.
I'm putting these single quotes here.
It's an empty string.
I want to delete that one empty string.
So two single quotes, Empty string.
Empty string, Empty string.
Also, let's clear out our message label.
Right.
Something.
Something happened where we don't need messages anymore.
Like a new purchase.
We close the window, something like that.
So we're just clearing everything out.
Cool.
We didn't call that yet, but keep that in mind.
Let's scroll down below our for loop the populates, our text buttons and maybe right underneath that
for loop before the events.
So I have my shop re event.
I'm going to make a function local function called is owned.
We're going to check to see if we own the thing that we're buying.
We don't want to buy things twice.
I'm going to pass in a player.
Although player is global in this script, I may want to break this script out, this function out somewhere
else.
I'm going to pass it in.
And then the item, the item that we're checking for, see if it's owned.
I need to get a character to see if it's on my character.
So if it's a hat, I might be wearing it, or if it's a gun, it might be my hand.
We're going to need the character.
We're going to get that from the player.
So player, dot character or player dot character added.
Wait, just in case the character is not quite ready, we're going to wait for the character at an event
to fire that says, Hey, wait there till that fires, and then we're going to have the character.
Char is going to have the character pretty good.
All right.
And now what we're going to do is we're going to check to see if we can find an own item on the character.
When we do a find first child.
No, no, no speech Quotes of type, item of name item.
So we're passing a string in here, so we're going to pass the string in, let's say simple pistol.
We're going to look in the character and see if we find it.
If we do, we own the item.
At least it's on a character.
So I'll do an if owned item.
Then let's send a message.
Message label text equals bound the item exclamation mark.
It was equipped, it was equipped, it was on the character.
Then we're going to return true, right?
So when I call this function, the return value is going to be a true if it was actually on the character,
but it might be in the backpack.
So I'm going to get that owned item again.
If we get down here.
We know that this didn't happen, right?
We didn't return it.
True.
I'm going to get owned item.
I'm going to look at the player and on the player there's something called a backpack, right?
That's the little squares down on the bottom of your screen as the pistol and the lemon and then the
backpack.
We can do a find first child.
And then if we find the item, oh, it's in the backpack.
So I'm going to check again.
If I owned item, then why did I do this twice?
Why didn't I just combine these ifs?
Well, I just wanted to show you the difference that sometimes it's equipped, sometimes it's in the
backpack.
You could certainly could combine those.
Right.
But now I thought that would be kind of cool to see how it's how you can look for things that are in
different places.
So we got our message.
Label text equals, let's say, found the item, but this time it was in the backpack.
And that's nothing good.
Oh, don't forget.
We got to return.
Right.
We found it.
Return True.
All right, so those are the two cases that we're going to look for.
If it's owned.
We don't have any other places.
We're going to put it.
And now down here in the activated, right, this is where we do the purchase.
We have the buy button, we activated it and we need to check to see if it's owned right here.
We're checking to see that somebody selected something.
Right.
The text is not equal to the empty string.
So let me put a note here.
I'm going to say something was selected.
That's the F statement.
I'll say if something was selected, because this is going to get a little bit a little bit hard, because
what I'm going to do is right in between these two s, I'm going to add another F, I'm going to say,
if not is owned, we're going to pass in the player and the item, but we don't have the item.
What we do is we have the preview name text, which is actually the item.
Copy.
Paste.
So if not is owned passing the player, passing the thing we're checking for then down here above where
it says if something was selected, put another end, let's format go up to here format document, that's
pretty good.
So now we're only going to go we're going to check to see if it was owned.
We're going to get a message.
If it is owned.
If it's not, we'll go in here, see if there's enough money.
What if there's not enough money?
Let's get rid of this print statement.
I put a m g ll be ll dot text equals.
I'm going to make that a capital n not enough money, maybe an exclamation mark.
And then down here, I don't need this print anymore.
Buying is going to be obvious.
We're actually going to buy it.
Oops, This got a little bit here.
Let me let me stress that out a little bit.
There we go.
Under the shop fire.
Ari, I think I'll do my clear, clear fields.
So we bought something.
We're going to clear the fields out.
And then I think I'm going to close my window.
We bought it.
Boom!
Close it.
Shop frame.
Dot visible equals false.
We're going to close that.
I think I'm going to get my clear fields and I'm going to put them when I open the shop to right just
in case I had something selected.
I go back to the shop.
I may not want that anymore.
I don't want to accidentally buy it.
So I'll do a clear field here and you can do it before or after the ding.
It doesn't matter.
You can put it anywhere in here.
I don't know why I put it in the middle.
All right.
I think we're good to go.
I think we got everything.
Let's try it.
Just got back real quick is That looks good.
We didn't do anything with a for loop for the tax fields are clear.
Fields is good.
And then we have our message label to find.
All right.
Play.
And I got 2150 points, so I should have enough money to make some purchases.
Simple pistol.
I'm going to buy it.
There you go.
I got it.
What happens if I open this up?
Fields are cleared.
That's good.
Maybe buy this again.
You found the item?
It was in your backpack.
What if I'm carrying it?
You can't see that I'm carrying it.
But I hit that.
I'm going to buy it again.
I found the item.
It was equipped.
All right, That's pretty cool.
What about the fabulous Lemon 2000?
So we don't have enough money.
Let's buy it.
Oh, not enough money.
I think that's pretty cool.
So we've got we've got a fairly highly functional store going.
The one thing, though, we don't persist the object.
So we bought this.
If I leave the game, if I come back, it's gone.
What happens if I die?
That.
Ah, Bomber gone and I'm out 1000 bucks.
So you'll have to make decisions whether you want to save or not.
In the next video, I'm going to show you how to save it.